package com.github.tangyi.exam.service.course;

import cn.hutool.core.util.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.tangyi.api.exam.dto.CourseCertDto;
import com.github.tangyi.api.exam.model.CourseCert;
import com.github.tangyi.api.exam.service.ICourseCertService;
import com.github.tangyi.common.service.CrudService;
import com.github.tangyi.common.utils.SysUtil;
import com.github.tangyi.exam.mapper.CourseCertMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.github.tangyi.constants.ExamCacheName;

@Slf4j
@Service
@AllArgsConstructor
public class CourseCertService extends CrudService<CourseCertMapper, CourseCert> implements ICourseCertService,ExamCacheName {

	@Override
	public CourseCert get(Long id) {
		return super.get(id);
	}

	@Override
	@Transactional
	public int insert(CourseCert courseCert) {
        courseCert.setCommonValue();
		return super.insert(courseCert);
	}

	@Override
	@Transactional
	public int update(CourseCert courseCert) {
        courseCert.setCommonValue();
		return super.update(courseCert);
	}

	@Override
	@Transactional
	public int delete(CourseCert courseCert) {
		return super.delete(courseCert);
	}

	@Override
	@Transactional
	public int deleteAll(Long[] ids) {
		return super.deleteAll(ids);
	}

    public PageInfo<CourseCertDto> list(CourseCertDto courseCert, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		courseCert.setTenantCode(SysUtil.getTenantCode());
		return PageInfo.of(dao.list(courseCert));
    }
}
